import type { UniFormsRules } from '@uni-helper/uni-ui-types'

/** 项目表单规则 */
export const ProjectFormRules: UniFormsRules = {
  projectName: {
    rules: [
      {
        required: true,
        errorMessage: '请输入项目名称',
      },
      {
        maxLength: 20,
        errorMessage: '项目名称不超过{maxLength}个字',
      },
      {
        // 自定义校验
        validateFunction: (rule, value, data, callback) => {
          if (value.length < 5) {
            callback('项目名称不能少于5个字符')
          }
          return true
        },
      },
    ],
  },
  brief: {
    rules: [
      {
        required: true,
        errorMessage: '请输入项目简介',
      },
      {
        maxLength: 50,
        errorMessage: '项目简介不超过{maxLength}个字',
      },
      {
        // 自定义校验
        validateFunction: (rule, value, data, callback) => {
          if (value.length < 20) {
            callback('项目简介不能少于20个字符')
          }
          return true
        },
      },
    ],
  },
  implementationPlan: {
    rules: [
      {
        required: true,
        errorMessage: '请输入项目实施计划',
      },
      {
        maxLength: 200,
        errorMessage: '项目实施计划不超过{maxLength}个字',
      },
      {
        // 自定义校验
        validateFunction: (rule, value, data, callback) => {
          if (value.length < 50) {
            callback('项目简介不能少于50个字符')
          }
          return true
        },
      },
    ],
  },
  imgUrl: {
    rules: [
      {
        required: true,
        errorMessage: '请添加项目图片',
      },
    ],
  },
  projectDescHtml: {
    rules: [
      {
        required: true,
        errorMessage: '请输入简介详情',
      },
      {
        maxLength: 2000,
        errorMessage: '活动简介不超过{maxLength}个字符',
      },
      {
        // 自定义校验
        validateFunction: (rule, value, data, callback) => {
          if (value.length < 50) {
            callback('活动简介不能少于50个字符')
          }
          return true
        },
      },
    ],
  },
  status: {
    rules: [
      {
        required: true,
        errorMessage: '请选择项目状态',
      },
    ],
  },
  targetAmount: {
    rules: [
      {
        required: true,
        errorMessage: '请输入如目标筹集金额',
      },
      {
        format: 'number',
        errorMessage: '请输入数字',
      },
      {
        minimum: 1000,
        maximum: 10000000,
        errorMessage: '最少{minimum}元，最多{maximum}元',
      },
    ],
  },
}

/** 活动表单规则 */
export const ActivityFormRules: UniFormsRules = {
  activityName: {
    rules: [
      {
        required: true,
        errorMessage: '请输入活动名称',
      },
      {
        maxLength: 20,
        errorMessage: '活动名称不超过{maxLength}个字',
      },
      {
        // 自定义校验
        validateFunction: (rule, value, data, callback) => {
          if (value.length < 5) {
            callback('活动名称不能少于5个字符')
          }
          return true
        },
      },
    ],
  },
  brief: {
    rules: [
      {
        required: true,
        errorMessage: '请输入活动简介',
      },
      {
        maxLength: 50,
        errorMessage: '活动简介不超过{maxLength}个字',
      },
      {
        // 自定义校验
        validateFunction: (rule, value, data, callback) => {
          if (value.length < 20) {
            callback('活动简介不能少于20个字符')
          }
          return true
        },
      },
    ],
  },
  imgUrl: {
    rules: [
      {
        required: true,
        errorMessage: '请添加活动图片',
      },
    ],
  },
  startTimeAndEndTime: {
    rules: [
      {
        required: true,
        errorMessage: '请选择时间范围',
      },
    ],
  },
  address: {
    rules: [
      {
        required: true,
        errorMessage: '请输入活动地址',
      },
    ],
  },
  requireVolunteers: {
    rules: [
      {
        required: true,
        errorMessage: '请输入所需志愿者人数',
      },
      {
        format: 'number',
        errorMessage: '请输入数字',
      },
      {
        minimum: 5,
        maximum: 100,
        errorMessage: '最少{minimum}人，最多{maximum}人',
      },
    ],
  },
  status: {
    rules: [
      {
        required: true,
        errorMessage: '请选择活动状态',
      },
    ],
  },
  activityDescHtml: {
    rules: [
      {
        required: true,
        errorMessage: '请输入活动详情',
      },
      {
        maxLength: 2000,
        errorMessage: '活动详情不超过{maxLength}个字符',
      },
      {
        // 自定义校验
        validateFunction: (rule, value, data, callback) => {
          if (value.length < 50) {
            callback('活动详情不能少于50个字符')
          }
          return true
        },
      },
    ],
  },
}

/** 动态表单规则 */
export const DynamicFormRules: UniFormsRules = {
  title: {
    rules: [
      {
        required: true,
        errorMessage: '请输入项目名称',
      },
      {
        maxLength: 20,
        errorMessage: '项目名称不超过{maxLength}个字',
      },
      {
        // 自定义校验
        validateFunction: (rule, value, data, callback) => {
          if (value.length < 5) {
            callback('项目名称不能少于5个字符')
          }
          return true
        },
      },
    ],
  },
  content: {
    rules: [
      {
        required: true,
        errorMessage: '请输入项目名称',
      },
      {
        maxLength: 200,
        errorMessage: '项目名称不超过{maxLength}个字',
      },
      {
        // 自定义校验
        validateFunction: (rule, value, data, callback) => {
          if (value.length < 15) {
            callback('项目名称不能少于15个字符')
          }
          return true
        },
      },
    ],
  },
  imgUrl: {
    rules: [
      {
        required: true,
        errorMessage: '请选择动态图片',
      },
    ],
  },
}
